/**
 * 
 */
package com.pengpeng.android.framework;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author lilidan
 *
 */
public class EventContainer {

	private static EventContainer instance=new EventContainer();
	private Map<String,List<IEvent>> eventmap=null;
   
	private EventContainer()
    {
		eventmap=new HashMap<String,List<IEvent>>();
    }
    
    public static EventContainer getInstance()
    {
    	return instance;
    }
    
    public boolean subscribeEvent(String eventid,IEvent event)
    {
    	List<IEvent> eventlist=eventmap.get(eventid);
    	if(null==eventlist)
    	{
    		eventlist=new ArrayList<IEvent>();
    		if(null==eventlist)
        	{
    			return false;
        	}
    		eventmap.put(eventid, eventlist);
    	}
    	eventlist.add(event);	
    	
    	return true;
    }//subscribeEvent
    
    public boolean publishEvent(String eventid,Object paraobj)
    {
    	List<IEvent> eventlist=eventmap.get(eventid);
    	IEvent event;
    	if(null!=eventlist)
    	{
    		for(int i=0;i<eventlist.size();i++)
    		{
    			event=eventlist.get(i);
    			event.doEvent(paraobj);
    		}
    		return true;
    	}
    	return false;
    }//publishEvent
}
